package com.heima.search.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    // 声明队列
    @Bean
    public Queue articleIndexQueue() {
        return QueueBuilder.durable("article.index").build();
    }

    // 声明交换机
    @Bean
    public Exchange articleIndexExchange() {
        return ExchangeBuilder.topicExchange("article.index").durable(true).build();
    }

    // 绑定队列和交换机
    @Bean
    public Binding articleIndexBinding() {
        return BindingBuilder.bind(articleIndexQueue()).to(articleIndexExchange()).with("article.index.create").noargs();
    }

    @Bean
    public Jackson2JsonMessageConverter jackson2JsonMessageConverter() {
        return new Jackson2JsonMessageConverter();
    }
}
